package com.htfyun.eink.pw.draw.pen.epd.charcoal;

import com.htfyun.eink.pw.draw.pointer.PWPointer;

import java.util.List;

public class CharcoalParam {

    public int color = 0xFF000000;//offset_0x08
    public float configWidth;//width
    //    public float offset_0x10;//rotateAngle
    public boolean tiltEnabled = false;//tiltEnabled
    public final float tiltScale;//tiltScale
    public final BitmapData paletteBitmap;//offset_0x20;//paletteBitmap; QWORD
    //    public HeaderInfo headerInfo;//offset_0x28;
    public BitmapData mTextureBmp;//offset_0x30;
    public BitmapData mTextureMaskBmp;//offset_0x38 = 0L;
    public BitmapData mCompositeTextureBmp;//offset_0x40 = 0L;
    public BitmapData mCompositeMaskBmp;// offset_0x48 = 0L;
    public float distanceSum;//offset_0x50,(float*)->0x14
    public PWPointer previousPoint;//offset_0x58
    public int count = 0;

    public float strokeWidth;

    public CharcoalParam(boolean tiltEnable, float tiltScale) {
        tiltEnabled = tiltEnable;
        this.tiltScale = tiltScale;

        List<Integer> colors = BmpColorConstant.Instance.getColors();
        paletteBitmap = new BitmapData((int) Math.sqrt(colors.size()));
        int index = 0;
        for (int i = 0; i < paletteBitmap.width; i++) {
            for (int j = 0; j < paletteBitmap.height; j++) {
                if (i * j >= colors.size()) {
                    paletteBitmap.data[i][j] = 0xff000000;
                } else {
                    paletteBitmap.data[i][j] = colors.get(index++);
                }
            }
        }
    }

    public void setStrokeWidth(float strokeWidth) {
        this.strokeWidth = strokeWidth;
        this.configWidth = 5.0f + strokeWidth * 1.2f;
    }
}
